package Player

import scala.swing._
import swing.event._
import java.awt.image._
import javax.imageio.ImageIO._
import java.awt.Graphics
import scala.swing.BorderPanel
import javax.swing.JPanel
import javax.swing.ImageIcon
import javax.swing.table._

object Player extends SimpleGUIApplication {
  def top = new MainFrame {
    title = "LoginPage"

    val label1 = new Label { text = "Username:" }
    val text1 = new TextField(10);
    val label2 = new Label { text = "Password:" }
    val text2 = new PasswordField(10);
    val Signin = new Button { text = "SignIn" }
    val NewPlayer = new Label { text = "New to Virtual Casino " }
    val acc = new Button { text = "New Player" }
    val Casino = new Label { text = "VirtualCasino" }
    val casImg = new Label {
      icon = new ImageIcon("Login_BjImage.jpg")
    }
    val buttonPanel = new BoxPanel(Orientation.Vertical) {
      contents += Casino
      contents += casImg
    }
    val PlayerLoginPanel = new GridPanel(10, 10) {
      hGap = 5
      vGap = 5
      contents += acc
      contents += label1
      contents += text1
      contents += label2
      contents += text2
      contents += Signin
    }
    val Fname = new Label { text = "First Name :" }
    val Lname = new Label { text = "Last Name :" }
    val Uname = new Label { text = "Username : " }
    val email = new Label { text = "Email : " }
    val Address = new Label { text = "Address :" }
    val City = new Label { text = "City : " }
    val State = new Label { text = "State :" }
    val Country = new Label { text = "Country :" }
    val Ph = new Label { text = "Phone No : " }
    val Ftxt = new TextField(15); ;
    val Ltxt = new TextField(15);
    val Utxt = new TextField(15);
    val etxt = new TextField(15);
    val addr = new TextField(15);
    val acity = new TextField(15);
    val St = new ComboBox(List("AL", "AR", "AZ", "CA", "CT", "DE", "FL", "GA", "ID", "MI", "NY", "NJ"))
    val Coun = new TextField(15);
    val pno = new TextField(15);
    val save = new Button { text = "Save" }
    val cancel = new Button { text = "Cancel" }
    val Playername = new Label { text = "Player Name:" + text1.text }
    val SetBankRoll = new Button { text = "SetBankRoll" }
    val TBets = new Button { text = " Tables and Bets" }
    val bets = new Label { text = "Place your bet Here:" }
    val amt = new TextField(15);
    val Bet = new Button { text = "Bet" }
    val Help = new Button { text = "Help Me" }
    val exit = new Button { text = "Exit Casino" }
    val BetImage = new Label {
      icon = new ImageIcon("PlaceBet.jpg")
    }
    val BetFrame = new BoxPanel(Orientation.Vertical) {
      background = java.awt.Color.GREEN
      contents += BetImage
      border = Swing.EmptyBorder(10, 10, 10, 10)
    }

    val SideFrame = new GridPanel(10, 100) {
      hGap = 5
      vGap = 5
      background = java.awt.Color.GREEN
      contents += Playername
      contents += SetBankRoll
      contents += TBets
      contents.append(bets, amt)
      contents += Bet
      contents += Help
      contents += exit
      border = Swing.EmptyBorder(10, 0, 10, 10)
    }
    val SetLabel = new Label { text = "Set Bank Roll" }
    val card = new Label { text = "Enter your Amount  " }
    val Cardamt = new TextField(15);
    val Tcard = new Label { text = "Select your card type " }
    val Cname = new Label { text = "Name On Card  " }
    val CardName = new TextField(15);
    val Cnum = new Label { text = "Card Number " }
    val CardNum = new TextField(15);
    val Cardsec = new Label { text = "Security Code " }
    val cvv = new TextField(15);
    val Sub = new Button { text = "Submit" }
    val Can = new Button { text = "Cancel" }
    val CardType = new ButtonGroup
    val Visa = new RadioButton("Visa")
    val Master = new RadioButton("Master")
    val Discover = new RadioButton("Discover")
    val CButton = List(Visa, Master, Discover)
    CardType.buttons ++= CButton
    CardType.select(Visa)
    val myradios = new BoxPanel(Orientation.Horizontal) {
      contents ++= CButton
    }
    val Cexp = new Label { text = "Expiry Date" }
    val CardDate = new ComboBox(1 to 31)
    val CardMon = new ComboBox(List("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
    val Cardyr = new ComboBox(2011 to 2020)
    val CardExpiry = new BoxPanel(Orientation.Horizontal) {
      background = java.awt.Color.GRAY
      contents.append(Cexp, CardDate, CardMon, Cardyr)
      border = Swing.EmptyBorder(10, 10, 0, 10)
    }
    val space11 = new Label { text = "" }
    val CardFrame = new GridPanel(8, 8) {
      background = java.awt.Color.GRAY
      contents.append(SetLabel, space11)
      contents.append(card, Cardamt)
      contents.append(Tcard, myradios)
      contents.append(Cname, CardName)
      contents.append(Cnum, CardNum)
      contents.append(Cardsec, cvv)
      contents.append(Sub, Can)
      border = Swing.EmptyBorder(10, 10, 10, 10)
    }
    val Hit = new Button { text = "Hit" }
    val Stand = new Button { text = "Stand" }
    val DDown = new Button { text = "DoubleDown" }
    val Insurance = new Button { text = "Insurance" }
    val Surr = new Button { text = "Surrender" }
    val Br = new Button { text = "Break" }
    val TableImage = new Label {
      icon = new ImageIcon("BjTable.jpg")
    }
    val TableFn = new BoxPanel(Orientation.Horizontal) {
      background = java.awt.Color.GREEN
      contents.append(Hit, Stand, DDown, Insurance, Surr, Br)
      border = Swing.EmptyBorder(10, 0, 10, 0)
    }
    val TFrame = new GridPanel(1, 0) {
      hGap = 0
      vGap = 0
      background = java.awt.Color.GREEN
      contents.append(TableImage)
      border = Swing.EmptyBorder(10, 0, 10, 10)
    }
    val TbuttonPanel = new GridPanel(1, 0) {
      hGap = 0
      vGap = 0
      background = java.awt.Color.GREEN
      contents.append(TableFn)
      border = Swing.EmptyBorder(10, 0, 10, 10)
    }
    val TableFrame = new BoxPanel(Orientation.Vertical) {
      contents.append(TFrame, TbuttonPanel)
    }

    runGUI

    def runGUI {
      contents = new BorderPanel {
        add(buttonPanel, BorderPanel.Position.West)
        val label0 = new Label { text = "  " }
        add(label0, BorderPanel.Position.Center)
        add(PlayerLoginPanel, BorderPanel.Position.East)

        border = Swing.EmptyBorder(30, 30, 30, 30)
      }

      listenTo(acc, Signin) //For the Login Screen
      reactions += {
        case ButtonClicked(`acc`) => runNewAcc
        case ButtonClicked(`Signin`) => runSignin
      }

      def runNewAcc {
        title = "New Player Account"
        contents = new GridPanel(10, 0) {
          contents.append(Fname, Ftxt)
          contents.append(Lname, Ltxt)
          contents.append(Uname, Utxt)
          contents.append(email, etxt)
          contents.append(Address, addr)
          contents.append(City, acity)
          contents.append(State, St)
          contents.append(Country, Coun)
          contents.append(Ph, pno)
          contents.append(save, cancel)
          border = Swing.EmptyBorder(10, 10, 10, 10)
        }
      }

      def runSignin {
        title = "Bj_House"
        contents = new BoxPanel(Orientation.Horizontal) {
          contents += SideFrame
          contents += BetFrame
          border = Swing.EmptyBorder(10, 0, 10, 10)
        }

      }

      listenTo(save, cancel) //For the Login Screen
      reactions += {
        case ButtonClicked(`save`) => runsave
        case ButtonClicked(`cancel`) => runcancel
      }
      def runsave {
          Dialog.showMessage(save,"Player Registered")
      
        Player.top.visible = true
      }
      def runcancel {
        Player.top.visible = true
      }

      listenTo(SetBankRoll, TBets, Bet, Help, exit)
      reactions += {
        case ButtonClicked(`SetBankRoll`) => runBankRoll
        case ButtonClicked(`TBets`) => runTBets
        case ButtonClicked(`Bet`) => runBet
        case ButtonClicked(`Help`)=>runHelp
        case ButtonClicked(`exit`)=>runexit
      }
      def runBankRoll {
        title = "Bj_SetBankRoll"
        contents = new BoxPanel(Orientation.Horizontal) {
          contents += SideFrame
          contents += CardFrame
          border = Swing.EmptyBorder(10, 20, 10, 20)
        }

      }
      def runTBets {
        title = "Tables and Bets"
        val PlaceBet = new Label { text = "Place your bet to start the game" }
        val tableModel = new DefaultTableModel(
          new Array[Array[AnyRef]](0, 3), // Data
          Array[AnyRef]("TableNo", "Min_Bet", "Max_Bet")) // Column names
        val table = new Table(3, 4) { model = tableModel }
        tableModel.addRow(Array[AnyRef]("TableNo", "Min_Bet", "Max_Bet"))
        tableModel.addRow(Array[AnyRef]("1", "$1", "$10"))
        tableModel.addRow(Array[AnyRef]("2", "$11", "$50"))
        tableModel.addRow(Array[AnyRef]("3", "$51", "$100"))
        tableModel.addRow(Array[AnyRef]("4", "$101", "$200"))
        tableModel.addRow(Array[AnyRef]("5", "$201", "$500"))
        tableModel.addRow(Array[AnyRef]("6", "$501", "$1000"))
        tableModel.addRow(Array[AnyRef]("7", "$1001", "$5000"))
        val tablePanel = new BoxPanel(Orientation.Vertical) {
          background = java.awt.Color.GRAY
          contents += PlaceBet
          contents += table
          border = Swing.EmptyBorder(110, 10, 70, 10)
        }
        contents = new BoxPanel(Orientation.Horizontal) {
          contents += SideFrame
          contents += tablePanel
          border = Swing.EmptyBorder(10, 10, 10, 10)
        }
      }
      def runBet {
        title = "Bj_Table"
        contents = new BoxPanel(Orientation.Horizontal) {
          contents += SideFrame
          contents += TableFrame
          border = Swing.EmptyBorder(10, 10, 0, 10)
        }
      }
      def runHelp{
        Dialog.showMessage(Help,"Refer to http://www.onlineblackjackguru.com/Blackjack-Rules.html")
      }
      def runexit{
        close()
      }
      listenTo(Sub, Can) //For the Login Screen
      reactions += {
        case ButtonClicked(`Sub`) => runsub
        case ButtonClicked(`Can`) => runcan
      }
      def runsub{
        Dialog.showMessage(Sub,Cardamt.text)
      }
      def runcan{
         title = "Bj_House"
         contents = new BoxPanel(Orientation.Horizontal) {
          contents += SideFrame
          contents += BetFrame
          border = Swing.EmptyBorder(10, 10, 10, 10)
        }
      }
    }

  }

}
